<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
    <script src="./heroes.js"></script>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="role in roles" @click="clickHandler(role.cn)">
          {{role.cn}}
        </li>
      </ul>
      <ul>
        <li v-for="hero in list">{{hero.name}}<mark>{{hero.role}}</mark></li>
      </ul>
    </div>
    <script>
      new Vue({
        el: "#app",
        data: {
          roles: [
            { cn: "全部", en: "all" },
            { cn: "重装", en: "tanks" },
            { cn: "输出", en: "damages" },
            { cn: "支援", en: "supports" },
          ],
          // 可以通过计算属性算出来
          heroes: heroes,
          current: "全部",
        },
        methods: {
          clickHandler: function (text) {
            console.log(text);
            this.current = text;
          },
        },
        computed: {
          tanks: function () {
            return this.heroes.filter((h) => h.id === "tank");
          },
          damages: function () {
            return this.heroes.filter((h) => h.id === "damage");
          },
          supports: function () {
            return this.heroes.filter((h) => h.id === "support");
          },

          list: function () {
            switch (this.current) {
              case "重装":
                return this.tanks;
                break;
              case "输出":
                return this.damages;
                break;
              case "支援":
                return this.supports;
                break;

              default:
                return this.heroes;
                break;
            }
          },
        },
      });
    </script>
  </body>
</html>
